/**
 * Created by yunpeng on 2014/12/4.
 */
var Table = require('../utils/Table').Table;

var CarNum = function(carbrand, cbid, num, createtime) {
    this.carbrand = carbrand;
    this.num = num;
    this.cbid = cbid;
    this.num = num;
    this.createtime = createtime;
    if (typeof this.save != 'function') {//仅在第一次调用的初始化
        CarNum.prototype.save = function(){
            var sql = 'insert into CarNum set ?';
            db.execQuery(sql,this,function(result){
                console.log(result);
            });
        };
    }
    if (typeof this.getCarNumList!='function'){
        CarNum.prototype.getCarNumList = function(id,callback){

            var sql = "select * from carnum c where c.cbid="+id;

            new Table().executeSql(sql,[],function(err, result){
                if(err){
                    debug(err);
                    callback(['']);
                }else{
                    callback(result);
                }
            });
        }

    }

    if (typeof this.getCarBrandList!='function'){
        CarNum.prototype.getCarBrandList = function(callback){

            var sql = "select * from carbrand cb ORDER BY  CONVERT( cb.carbrand USING gbk ) COLLATE gbk_chinese_ci ASC";

            new Table().executeSql(sql,[],function(err, result){
                if(err){
                    debug(err);
                    callback(['']);
                }else{
                    callback(result);
                }
            })
        }

    }
}
exports.CarNum = CarNum;